package com.itheima.demo5.server;

import com.itheima.demo5.ui.User;

import java.net.ServerSocket;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;

public class Server {

    public static final Map<Socket, User> map = new HashMap<>();
    public static void main(String[] args) {
        System.out.println("服务器启动...");

        try(
                ServerSocket server = new ServerSocket(Constant.PORT);
                ) {
            while(true){
                System.out.println("等待客户端连接...");
                Socket socket = server.accept();
                System.out.println("客户端连接成功！");
                new ServerThread(socket).start();
                System.out.println("客户端的ip为：" + socket.getInetAddress());
                System.out.println("客户端的端口为：" + socket.getPort());
                System.out.println("------------------------------------------");
            }
        } catch (Exception e){
            e.printStackTrace();
        }
    }
}
